package com.miplus.ccrm.core.controller;

import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.JSysUser;
import com.miplus.ccrm.common.PageData;
import com.miplus.ccrm.common.R;
import com.miplus.ccrm.core.controller.vo.conf.CmsResVo;
import com.miplus.ccrm.core.controller.vo.file.UploadResVo;
import com.miplus.ccrm.core.controller.vo.voiceprint.*;
import com.miplus.ccrm.core.security.JCommonData;
import com.miplus.ccrm.core.service.voiceprint.VoiceModelLibraryService;
import com.miplus.ccrm.core.service.voiceprint.VoicePrintLibraryService;
import org.jetbrains.annotations.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 2-12.声纹识别接口
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/voiceprint")
public class VoiceprintVontroller {

    @Resource
    private JCommonData jCommonData;
    @Resource
    private VoiceModelLibraryService modelLibraryService;


    /**
     * 声纹模型 LIST.PAGE
     * @param reqVo
     * @return
     */
    @PostMapping("/customerModelPage")
    public R<PageData<CustomerModelPageResVo>> customerModelPage(@RequestBody @Validated CustomerModelPageReqVo reqVo){
        JSysUser user= jCommonData.getCurrUsr();
        return R.SuccessPage(modelLibraryService.customerModelPage(user,reqVo));
    }

    /**
     * 声纹模型详情 INFO
     * @param reqVo
     * @return
     */
    @PostMapping("/customerModelInfo")
    public R<CustomerModelInfoResVo> customerModelInfo(@RequestBody @Validated CustomerModelInfoReqVo reqVo){
        return R.Success(modelLibraryService.customerModelInfo(reqVo));
    }



    /**
     * 训练语音模型
     * @param reqVo
     * @return
     */
    @PostMapping("/trainModel")
    public R<CmdResVo>trainModel(@RequestBody @Validated CustomerModelInfoReqVo reqVo){

        return R.Success(modelLibraryService.trainModel(reqVo));
    }


    /**
     * 客户注册声纹 ADD
     * @return
     */
    @PostMapping("/customerVoiceRegi")
    public R<CmdResVo>customerVoiceRegi(@RequestBody @Validated CustomerVoiceRegiReqVo reqVo){

        return R.Success(modelLibraryService.customerVoiceRegi(reqVo));
    }

    /**
     * 客户比对声纹 上传
     * @return
     */
    @PostMapping("/customerCompareRegi")
    public R<CmdResVo>customerCompareRegi(@RequestBody @Validated CustomerVoiceRegiReqVo reqVo){

        return R.Success(modelLibraryService.customerCompareRegi(reqVo));
    }



    /**
     * 声纹库表 LIST.PAGE
     * @return
     */
    @PostMapping("/voicePrintLibraryPage")
    public R<PageData<VoicePrintLibraryPageResVo>>vpPage(@RequestBody @Validated VoicePrintLibraryPageReqVo reqVo){
        return R.SuccessPage(modelLibraryService.vpPage(reqVo));
    }

    /**
     * 删除声纹 DEL
     * @return
     */
    @GetMapping("/voicePrintLibraryDel")
    public R<CmdResVo>vpDel(@RequestParam @NotNull String id){
        return R.Success(modelLibraryService.vpDel(id));
    }


    /**
     * 声纹分析对比
     * @param id
     * @return
     */
    @GetMapping("/verifyModel")
    public R<CmdResVo>verifymodel(@RequestParam @NotNull String id){
        return R.Success(modelLibraryService.verifyModel(id));
    }


    /**
     * 调听声纹
     */
    @RequestMapping(value = "play", method = RequestMethod.GET)
    public R play(String id, HttpServletResponse response) {
        modelLibraryService.OnPlayFile(id,response);
        return R.Success();
    }


    /**
     * 上载附件文件
     */

    @RequestMapping(value = "upload", method = RequestMethod.POST)
    public R<UploadResVo> upload(@RequestParam("file") MultipartFile file) {
        return R.Success(modelLibraryService.doUpload(file));
    }
}
